package com.ohs.controller.admin;

import com.ohs.pojo.Admin;
import com.ohs.pojo.Product;
import com.ohs.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IAdminService iAdminService;

    @GetMapping("/toAdminLoginPage")
    public String toAdminLoginPage(HttpSession session){
        session.invalidate();
        return "admin/adminLogin";
    }

    @PostMapping("/doAdminLogin")
    public String doAdminLogin(Admin admin, Model model){
        return this.iAdminService.doAdminLogin(admin, model);
    }

    //分页查询
    @RequestMapping("/selectAllGoodsByPage")
    public String selectAllGoodsByPage(@RequestParam(defaultValue = "1") Integer currentPage, Model model){
        return this.iAdminService.selectAllGoodsByPage(currentPage, model);
    }

    //跳转的添加页面
    @GetMapping("/toAddProductPage")
    public String toAddProductPage(){
        return "admin/addProduct";
    }

    @PostMapping("/addProduct")
    public String addProduct(Product product, MultipartFile fileName, HttpSession session){
        return this.iAdminService.addProduct(product, fileName, session);
    }

    @RequestMapping("/touUpdateProductPage")
    public String touUpdateProductPage(Integer proId, Model model){
        return this.iAdminService.touUpdateProductPage(proId, model);
    }

    @PostMapping("/updateProduct")
    public String updateProduct(Product product){
        return this.iAdminService.updateProduct(product);
    }
    @RequestMapping("/doDeleteProductPage")
    public String doDeleteProductPage(Integer proId){
     String view= this.iAdminService.doDeleteProductPage(proId);
     return view;
    }
    //去到全部用户页面
    @GetMapping("/toAllUsers")
    public String toAllUsers(@RequestParam(defaultValue = "1") Integer currentPage,Model model){
        return iAdminService.findAllUsers(currentPage,model);

    }

}
